home *** CD-ROM | disk | FTP | other *** search
/ All for Cell Phones: Sony Ericsson / Sony-Ericsson 2004.iso / Java / HTetris / htetris.jar / tetris / MainMenu.class (.txt) < prev    next >
Encoding:
Java Class File  |  2002-07-19  |  4.4 KB  |  116 lines

  1. package tetris;
  2.  
  3. import javax.microedition.lcdui.Command;
  4. import javax.microedition.lcdui.CommandListener;
  5. import javax.microedition.lcdui.Display;
  6. import javax.microedition.lcdui.Displayable;
  7. import javax.microedition.lcdui.Form;
  8. import javax.microedition.lcdui.Image;
  9. import javax.microedition.lcdui.List;
  10.  
  11. public class MainMenu extends List implements CommandListener {
  12.    static byte continueMenuItemNr = 6;
  13.    boolean savedGame = false;
  14.  
  15.    public MainMenu() {
  16.       super("HTetris", 3);
  17.  
  18.       try {
  19.          this.jbInit();
  20.       } catch (Exception e) {
  21.          ((Throwable)e).printStackTrace();
  22.       }
  23.  
  24.    }
  25.  
  26.    private void jbInit() throws Exception {
  27.       ((Displayable)this).setCommandListener(this);
  28.       ((Displayable)this).addCommand(new Command("Exit", 7, 1));
  29.       ((List)this).append("New game", (Image)null);
  30.       ((List)this).append("High scores", (Image)null);
  31.       ((List)this).append("Options", (Image)null);
  32.       ((List)this).append("Redefine keys", (Image)null);
  33.       ((List)this).append("Help", (Image)null);
  34.       ((List)this).append("About", (Image)null);
  35.       if (GameScreen.existsSavedGame()) {
  36.          this.savedGame = true;
  37.          this.addContinue();
  38.       }
  39.  
  40.    }
  41.  
  42.    public void addContinue() {
  43.       ((List)this).append("Continue", (Image)null);
  44.       ((List)this).setSelectedIndex(continueMenuItemNr, true);
  45.    }
  46.  
  47.    public void redefineKeys(Displayable d) {
  48.       Options.optDefaultKeys = false;
  49.       Options.opt2.setSelectedIndex(0, false);
  50.       Options.openStore();
  51.       Options.saveOptions();
  52.       Options.closeStore();
  53.       Display.getDisplay(TetrisMIDlet.instance).setCurrent(new GetKey(d));
  54.    }
  55.  
  56.    public void commandAction(Command command, Displayable displayable) {
  57.       if (command.getCommandType() == 7) {
  58.          TetrisMIDlet.quitApp();
  59.       }
  60.  
  61.       if (command.getCommandType() == 2) {
  62.          Display.getDisplay(TetrisMIDlet.instance).setCurrent(this);
  63.       }
  64.  
  65.       if (command == List.SELECT_COMMAND) {
  66.          switch (((List)this).getSelectedIndex()) {
  67.             case 0:
  68.                if (((List)this).size() > continueMenuItemNr) {
  69.                   ((List)this).delete(continueMenuItemNr);
  70.                   ((List)this).setSelectedIndex(0, true);
  71.                }
  72.  
  73.                Display.getDisplay(TetrisMIDlet.instance).setCurrent(TetrisMIDlet.gameScreen);
  74.                TetrisMIDlet.gameScreen.startGame();
  75.                break;
  76.             case 1:
  77.                TetrisMIDlet.highScores.updateScores();
  78.                Display.getDisplay(TetrisMIDlet.instance).setCurrent(TetrisMIDlet.highScores);
  79.                break;
  80.             case 2:
  81.                Display.getDisplay(TetrisMIDlet.instance).setCurrent(TetrisMIDlet.options);
  82.                break;
  83.             case 3:
  84.                this.redefineKeys(this);
  85.                break;
  86.             case 4:
  87.                Form help = new Form("Help");
  88.                help.append("This is a classic tetris game. Your aim is to put the falling blocks in the way they form full rows, which will dissappear.");
  89.                help.append("\n\n".concat(String.valueOf(String.valueOf(Options.currentKeys(true)))));
  90.                ((Displayable)help).setCommandListener(this);
  91.                ((Displayable)help).addCommand(new Command("Back", 2, 1));
  92.                Display.getDisplay(TetrisMIDlet.instance).setCurrent(help);
  93.                break;
  94.             case 5:
  95.                Form about = new Form("About");
  96.                String x = TetrisMIDlet.instance.getAppProperty("MIDlet-Version");
  97.                about.append("HTetris ".concat(String.valueOf(String.valueOf(x == null ? "" : x))));
  98.                about.append("\n(c) 2002\nCopyrights by\nCsomos Tamas");
  99.                ((Displayable)about).setCommandListener(this);
  100.                ((Displayable)about).addCommand(new Command("Back", 2, 1));
  101.                Display.getDisplay(TetrisMIDlet.instance).setCurrent(about);
  102.                break;
  103.             case 6:
  104.                ((List)this).delete(continueMenuItemNr);
  105.                ((List)this).setSelectedIndex(0, true);
  106.                if (!this.savedGame || TetrisMIDlet.gameScreen.loadGame()) {
  107.                   this.savedGame = false;
  108.                   Display.getDisplay(TetrisMIDlet.instance).setCurrent(TetrisMIDlet.gameScreen);
  109.                   TetrisMIDlet.gameScreen.resumeGame();
  110.                }
  111.          }
  112.       }
  113.  
  114.    }
  115. }
  116.